package cj.web.tel.utils;

import java.util.HashMap;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cj.web.admin.dao.ConfigInfoDAO;
/** 
 * @author ROC 
 * 2010年4月5日18:26:55 
 * 实现getAllInfo方法，取得所有常用字典表里的数据 
 *  
 * */  
public class GetDictionaryInfo {  
	
	/**
	 * https://blog.csdn.net/peng_wu01/article/details/5453361
	 * 
	 * reloadDictionaryInfoMap();实现起来时比较困难的，要在GetDictionaryInfo 取到ServletContext，
	 * 而且要必须取到第一次实例的GetDictionaryInfo ，所有有一个东西很好用，就是Spring的context,取到他的方式
	 * 
	 * 刷新
	 * GetDictionaryInfo.getInstance().reloadDictionaryInfoMap();  
	 * 
	 * 赋值
	 * private static WebApplicationContext springContext;  
	 * springContext = WebApplicationContextUtils.getWebApplicationContext(_servletContext);  
	 */
	public final static String COLUMNS = "COLUMNS_CODE";
	
	public final static String GROUPINFOR = "GROUPINFOR_CODE";
	
	public final static String LABEL = "LABEL_CODE";
	
	public final static String GNJG = "GNJG_CODE";
	
	public final static String GWJG = "GWJG_CODE";
	
	public final static String NSJG = "NSJG_CODE";

	@Autowired
    private ConfigInfoDAO configInfoDAO;
      
    public GetDictionaryInfo(){  
        super();  
    }  
    private static WebApplicationContext springContext;//这个是为了取springContext  
    public static ServletContext _servletContext;//这个是为了取servletContext  
    private static GetDictionaryInfo _instance;   
    public static HashMap<String,Object> dictionaryInfoMap = new HashMap<String, Object>();  
    
    public static GetDictionaryInfo getInstance() {  
        springContext = WebApplicationContextUtils  
        .getWebApplicationContext(_servletContext);  
        if(null == _instance)  
            _instance = (GetDictionaryInfo)springContext.getBean("getDictionaryInfo");  
        return _instance;  
          
    }  
    
    public  void getAllInfo() throws NumberFormatException, Exception {  
        System.out.println("%%%%%%%%%%系统启动加载......");  
        String columnsCodeValue = "";
        
		dictionaryInfoMap.put("repNsjgLis", null);
		
        System.out.println("@@@@@@@@@@数据打包完毕，全部放进了dictionaryInfoMap！");  
    }  
    
    /** 
     * 重新加载字典表数据！ 
     * @throws Exception 
     * @throws NumberFormatException 
     * */  
    public void reloadDictionaryInfoMap() throws NumberFormatException, Exception {  
        System.out.println("==========~~~~~~~~~~系统开始重新加载字典表");  
        dictionaryInfoMap.clear();  
        System.out.println("==========~~~~~~~~~~字典表MAP,清空成功！");  
        getAllInfo();  
        System.out.println("==========~~~~~~~~~~重新加载字典表成功");  
    }  
      
    public HashMap<String, Object> getDictionaryInfoMap() {  
        return dictionaryInfoMap;  
    }  
    public void setDictionaryInfoMap(HashMap<String, Object> dictionaryInfoMap) {  
        this.dictionaryInfoMap = dictionaryInfoMap;  
    }  
}  